import  { constantRoutes, asyncRoutes } from '@/router/index.js'
const state = {
  routes: constantRoutes
}
const mutations = {
  setRoutes(state, payload) {
    state.routes = [...constantRoutes, ...payload]
  }
}
const actions = {
  getRoutes(ctx, menus) {
    const newRoutes = asyncRoutes.filter(item => {
      const mypath = item.path.replace('/', '')
      return menus.indexOf(mypath) !== -1
    })
    ctx.commit('setRoutes', newRoutes)
    return newRoutes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}